// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	11/6/2014 8:39:00 PM				
// -----------------------------

#include "SawtoothOscillator.h"

SawtoothOscillator::SawtoothOscillator()
	: Oscillator(SoundWaveType::Sawtooth)
{
}

SawtoothOscillator::~SawtoothOscillator()
{
}

Float SawtoothOscillator::Sample(Float t) const
{
	// Generate the Sawtooth Wave
	Float s = 0.0f;
	for (UInt32 h = 1; h <= Harmonics; ++h)
	{
		Float sh = Math::Sin(2.0f * Math::Pi * (Float)h * Frequency * t);
		sh /= (Float)h;
		s += sh;
	}
	s = ((Amplitude / 2.0f) - (Amplitude / Math::Pi)) * s;

	return s;
}